﻿using CommunityToolkit.Mvvm.ComponentModel;
using System.Collections.ObjectModel;
using System.Text.RegularExpressions;
using System.Windows.Media;

namespace 充电桩上位机.Model.FTRegisters;

public class HelpFTRegistersModel : ObservableObject
{
    private ObservableCollection<string> _fTRegOptionList = new();
    public ObservableCollection<string> FTRegOptionList
    {
        get => _fTRegOptionList;
        set => SetProperty(ref _fTRegOptionList, value);
    }
    private string _titleName = string.Empty;
    public string TitleName
    {
        get => _titleName;
        set => SetProperty(ref _titleName, value);
    }

    private Brush _workTitleColor = Brushes.Black;
    public Brush WorkTitleColor
    {
        get => _workTitleColor;
        set => SetProperty(ref _workTitleColor, value);
    }

    private bool _workTitle = new();
    public bool WorkTitle
    {
        get => _workTitle;
        set
        {
            if (value)
                WorkTitleColor = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#2563EB"));
            else
                WorkTitleColor = Brushes.Black;
            SetProperty(ref _workTitle, value);
        }
    }
    //unit 根据 Type 变化
    private string _connectorType = string.Empty;
    public string ConnectorType
    {
        get => _connectorType;
        set
        {
            if (!string.IsNullOrEmpty(value))
            {
                if (value.Contains("DC"))
                    Unit = "kW";
                else if (value.Contains("AC"))
                    Unit = "A";
                else
                    Unit = string.Empty;
            }
            SetProperty(ref _connectorType, value);
        }
    }

    private int _connectorIndex = -1;
    public int ConnectorIndex
    {
        get => _connectorIndex;
        set => SetProperty(ref _connectorIndex, value);
    }

    private string _signalShot = string.Empty;
    public string SignalShot
    {
        get => _signalShot;
        set {
            string pattern = @"^-?\d+$";
            Regex regex = new(pattern);
            if (regex.IsMatch(value))
            {
                SetProperty(ref _signalShot, value);
            }
        }
    }
    private string _unit = string.Empty;
    public string Unit
    {
        get => _unit;
        set => SetProperty(ref _unit, value);
    }
}
